package com.eastfair.venueservice.service.impl;

import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.api.BuilderRepairReportFeign;
import com.eastfair.home.dto.BuilderRepairReportDTO;
import com.eastfair.venueservice.service.VenueManageBuilderRepairReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * 搭建商报修申请 服务.
 *
 * @author dqq
 * @date 2022 /11/24
 */
@Service
@Slf4j
public class VenueManageBuilderRepairReportServiceImpl implements VenueManageBuilderRepairReportService {

    @Resource
    private BuilderRepairReportFeign builderRepairReportFeign;

    @Override
    public boolean completeRepairReport(BuilderRepairReportDTO builderRepairReportDTO) {
        log.info("completeRepairReport - 更新搭建商报修申请为已完成, builderRepairReportDTO={}", builderRepairReportDTO);
        R<Boolean> result = builderRepairReportFeign.completeRepairReport(builderRepairReportDTO);
        log.info("completeRepairReport - 完成, result={}", result);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    public boolean updateIsBookService(BuilderRepairReportDTO builderRepairReportDTO) {
        log.info("updateIsBookService - 更新搭建商报修申请是否预定了服务, builderRepairReportDTO={}", builderRepairReportDTO);
        R<Boolean> result = builderRepairReportFeign.updateIsBookService(builderRepairReportDTO);
        log.info("updateIsBookService - 更新搭建商报修申请是否预定了服务, result={}", result);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    public boolean updateIsBookService(String repairReportNumber, Integer isBookService) {
        BuilderRepairReportDTO builderRepairReportDTO = new BuilderRepairReportDTO();
        builderRepairReportDTO.setRepairReportNumber(repairReportNumber);
        builderRepairReportDTO.setIsBookService(isBookService);
        return updateIsBookService(builderRepairReportDTO);
    }

    @Override
    public boolean updateCompensateVenueAmount(BuilderRepairReportDTO builderRepairReportDTO) {
        log.info("updateCompensateVenueAmount - 更新搭建商报修申请需赔付场馆金额, builderRepairReportDTO={}", builderRepairReportDTO);
        R<Boolean> result = builderRepairReportFeign.updateCompensateVenueAmount(builderRepairReportDTO);
        log.info("updateCompensateVenueAmount - 更新搭建商报修申请需赔付场馆金额, result={}", result);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    public boolean updateCompensateVenueAmount(String repairReportNumber, BigDecimal compensateVenueAmount) {
        BuilderRepairReportDTO builderRepairReportDTO = new BuilderRepairReportDTO();
        builderRepairReportDTO.setRepairReportNumber(repairReportNumber);
        builderRepairReportDTO.setCompensateVenueAmount(compensateVenueAmount);
        return updateCompensateVenueAmount(builderRepairReportDTO);
    }
}